﻿using Exam.infranstuctrue.Dto.Request.Error;
using Exam.infranstuctrue.EFCore;
using Exam.infranstuctrue.IOC;
using Exam.infranstuctrue.Tools;
using Exam.infranstuctrue.Tools.Attributes;
using Exam.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Exam.Service.Instance
{
    [Iinjection]
    public class ErrorService : IErrorService
    {
        private readonly ErrorIOC _errorIOC;

        public ErrorService(ErrorIOC errorIOC)
        {
           _errorIOC = errorIOC;
        }

        public void AddActionLog(ErrorDto dto)
        {
            Actionlog actionlog = new Actionlog()
            {
                Alid = Config.GUID(),
                Alaction = dto.action,
                AlapiUrl = dto.url,
                AlcreateTime = DateTime.Now,
                Aldesc = null,
                Alip = dto.ip,
                Alparams = dto.paras,
                Alresult = dto.result,
                AlresultMessage = dto.message,
                Altype = dto.group,
                Alversion = dto.version,
                Aluid = dto.uid
            };
            _errorIOC._actionlogEFCoreService.Add(actionlog);
            int result = _errorIOC._actionlogEFCoreService.SaveChanges();
        }
        /// <summary>
        /// 错误列表
        /// </summary>
        /// <param name="dto"></param>
        public void AddError(ErrorDto dto)
        {
            Errorlog errorlog = new Errorlog()
            {
                Elid = Config.GUID(),
                Elapi = dto.url,
                ElcreateTime = DateTime.Now,
                Eldesc = null,
                Elip = dto.ip,
                Elmessage = dto.message,
                Elparams = dto.paras,
                Eluid = dto.uid
            };
            _errorIOC._errorEFCoreService.Add(errorlog);
            int result = _errorIOC._errorEFCoreService.SaveChanges();
        }
    }
}
